package studio.raptor.hub.in.server;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.apache.http.client.HttpClient;
import studio.raptor.hub.in.ServerProxy;
import studio.raptor.hub.in.entity.SoCompleteARPReq;

/**
 * Created by liuyong8 on 2017/7/27.
 */
public class SoCompleteARPProxy extends ServerProxy {
//    [{
//        "orderItemIds": [
//        1000000000059798,
//                1000000000059790,
//                1000000000059791,
//                1000000000005148,
//                1000000000005146,
//                1000000000005147
//    ]
//    }]


    public SoCompleteARPProxy(HttpClient httpClient) {
        super(httpClient);
    }

    @Override
    protected String handleResponse(String response) {
        DocumentContext sc = JsonPath.parse(response);
        Object object = sc.read("$.resultObject");
        String result = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
        if (result.startsWith("{")) {
            result = result.substring(1,result.length()-1);
        }
        return result;
    }

    @Override
    protected String getMessage(Long... params) {
        SoCompleteARPReq soCompleteARPReq = new SoCompleteARPReq();
        soCompleteARPReq.setOrderItemIds(params);
        String message = JSON.toJSONString(soCompleteARPReq);
        return message;
    }
}
